In [1]:
# common
import sys
import os
import os.path as op

# basic
import numpy as np
import pandas as pd
import xarray as xr
from time import time
import warnings
warnings.simplefilter('ignore')

# custom
from lib import calval

# functions
from lib import functions
In [2]:
# initial time to see the duration of the notebook
t0 = time()
In [3]:
# data 
p_data = op.join(os.getcwd(), 'data')

csiro      =  pd.read_pickle(op.join(p_data, 'hindcast', 'csiro_dataframe.pkl'))
satellite  =  xr.open_dataset(op.join(p_data, 'satellite', 'satellite_dataset.nc'))
buoy       =  pd.read_pickle(op.join(p_data, 'buoy', 'Bilbao-Vizcaya Ext.pkl'))

print('---------------------------------------------------')
print('Time wasted reading the data: ' + str(round(time()-t0, 2)) + ' s')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted reading the data: 0.06 s
---------------------------------------------------
In [4]:
t1 = time()
In [5]:
## creation of the main object

#######################################################
###   VALUES WILL HAVE TO BE INSERTED SO BE READY   ###
###   Satellite box :    South = 43.8               ###
###                      North = 44.2               ###
###                      West  = 356.2              ###
###                      East  = 356.6              ###
###   Time calibration:  False                      ###
###   Threshold :        0.015                      ###
#######################################################

# the threshold allows us to delete not relevant information

calval_case = calval.CalVal(hindcast=csiro, 
                            satellite=satellite,
                            buoy=buoy,
                            buoy_corrections=True)

# if buoy data does not exist, just delte the buoy and buoy_correction
# attributes, and then comment the methods that use the buoy information

print('---------------------------------------------------')
print('Time wasted initializing the constructor: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
--------------------------------------------------------
SATELLITE CALIBRATION will be performed
-------------------------------------------------------- 
 
Satellite box values: 
South latitude: 43.8
North latitude: 44.2
West latitude: 356.2
East latitude: 356.6
 
 
Selecting the satellite data choosed... 
 
Satellite length: 10390
Hindcast information able to calibrate: 360839 
 
Choose the way to calibrate the data: 
True: hindcast for each satellite 
False (empty box): satellite for each hindcast 
----- Select ----- : 
 
 
Performing the time calibration... 
 
Length of data to calibrate: 5461 
 
 
 
Constructing matrices and calibrating... 
 
This might take a few minutes... 

Sea... 

0.0% completed...


Swells 1, 2, 3... 

0.0% completed...
0.0% completed...
0.0% completed...


Value to set the umbral for not enough data to calibrate, 
this value can be from 0.01 to 0.03: 
----- Threshold ----- : 0.02
 
 
 
 
Params used for the SATELLITE calibration are: 
 
[1.21793192 1.11531269 0.9470322  1.1557174  1.18111607 1.
 0.99777061 1.         1.         1.         1.         1.
 0.96515552 1.03992115 1.04519449 1.20163806 1.         1.
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.13937011 1.0813723
 1.12826289 1.17171979]
 
 
Plotting just the data used to calibrate... 
 
Saving corrected results... 
 
This might take more than a few minutes... 

Sea... 

0.0% completed...


Swells 1, 2, 3... 

0.0% completed...
0.0% completed...
0.0% completed...
 
  
 
--------------------------------------------------------
BUOY CALIBRATION will be performed
-------------------------------------------------------- 
 
 
 
Constructing matrices and calibrating... 
 
This might take a few minutes... 

Sea... 

0.0% completed...


Swells 1, 2, 3... 

0.0% completed...
0.0% completed...
0.0% completed...


Value to set the umbral for not enough data to calibrate, 
this value can be from 0.01 to 0.03: 
----- Threshold ----- : 0.02
 
 
 
 
Params used for the BUOY calibration are: 
 
[1.02137022 0.96863021 0.86212164 0.8258302  1.         1.
 1.         1.         1.         1.         1.         1.
 0.89601481 1.00653646 1.05089847 1.05307368 1.         1.
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         0.95365576 1.02998954
 1.1126027  1.17649791]
 
 
Plotting just the data used to calibrate... 
 
Saving corrected results... 
 
This might take more than a few minutes... 

Sea... 

0.0% completed...


Swells 1, 2, 3... 

0.0% completed...
0.0% completed...
0.0% completed...
 
  
 
---------------------------------------------------
Time wasted initializing the constructor: 6.52 m
---------------------------------------------------
In [6]:
t1 = time()
In [7]:
# calval_case.hindcast_sat_corr.to_pickle(op.join(p_data, 'hindcast', 'csiro_dataframe_sat_corr.pkl'))
# calval_case.hindcast_buoy_corr.to_pickle(op.join(p_data, 'hindcast', 'csiro_dataframe_buoy_corr.pkl'))
In [8]:
# comparisons

#######################################################
###   VALUES WILL HAVE TO BE INSERTED SO BE READY   ###
###   Number of years :    3                        ###
###   Years :              2006 2007 2008           ###
#######################################################

calval_case.buoy_comparison('raw')
--------------------------------------------------------
RAW comparison will be performed
-------------------------------------------------------- 
 
Number of years: 3
Years separated by one space: 2006 2007 2008
 
 
Comparing data... 
 
In [9]:
calval_case.buoy_comparison('sat_corr')
--------------------------------------------------------
SAT_CORR comparison will be performed
-------------------------------------------------------- 
 
Number of years: 3
Years separated by one space: 2006 2007 2008
 
 
Comparing data... 
 
In [10]:
calval_case.buoy_comparison('buoy_corr')
--------------------------------------------------------
BUOY_CORR comparison will be performed
-------------------------------------------------------- 
 
Number of years: 3
Years separated by one space: 2006 2007 2008
 
 
Comparing data... 
 
In [11]:
print('---------------------------------------------------')
print('Time wasted comparing: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted comparing: 2.94 m
---------------------------------------------------
In [12]:
t1 = time()
In [13]:
# validations

calval_case.buoy_validation('raw')
--------------------------------------------------------
RAW VALIDATION will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [14]:
calval_case.buoy_validation('sat_corr')
--------------------------------------------------------
SAT_CORR VALIDATION will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [15]:
calval_case.buoy_validation('buoy_corr')
--------------------------------------------------------
BUOY_CORR VALIDATION will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [16]:
print('---------------------------------------------------')
print('Time wasted validating: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted validating: 7.2 m
---------------------------------------------------
In [17]:
print('---------------------------------------------------')
print('TOTAL time of the script: ' + str(round((time()-t0)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
TOTAL time of the script: 16.74 m
---------------------------------------------------